<?php include("header.php");



// get fields from form org_registration.php
$userName =  mysql_real_escape_string($_POST["userName"]);
$password =  mysql_real_escape_string($_POST["password"]);
$orgName =  mysql_real_escape_string($_POST["organization"]);
$firstName = mysql_real_escape_string($_POST["cFName"]);
$lastName = mysql_real_escape_string($_POST["cLName"]);
$areaCode = mysql_real_escape_string($_POST["areaCode"]);
$prefix = mysql_real_escape_string($_POST["pnum3"]);
$lineNumber = mysql_real_escape_string($_POST["pnum4"]);
$streetAddress = mysql_real_escape_string($_POST["streetAdd"]);
$street2 = mysql_real_escape_string($_POST["add2"]);
$city = mysql_real_escape_string($_POST["city"]);
$state = mysql_real_escape_string($_POST["state"]);
$zip = mysql_real_escape_string($_POST["zip"]);
$email =  mysql_real_escape_string($_POST["email"]);
$website =  mysql_real_escape_string($_POST["webSite"]);
$additional = mysql_real_escape_string($_POST["element_9"]);

$query = <<<END
	SELECT COUNT(`orgID`) FROM `organizations`;
END;

$result = mysql_query($query, $connection);
if ($result == false){
	mysql_close($connection);
	die("Registration Failed:".mysql_error($connection));
}
	
$result = mysql_fetch_array($result);
$orgID = $result[0] + 1;

$query = <<<END
	INSERT INTO `organizations` 
	VALUES (
		'$orgID',
		'$orgName',
		'$firstName',
		'$lastName',
		'$areaCode',
		'$prefix',
		'$lineNumber',
		'$streetAddress',
		'$street2',
		'$city',
		'$state',
		'$zip',
		'$email',
		'$website',
		'$additional'
		);
END;





if (!mysql_query($query, $connection))
	die("Failed to Register Org: " . mysql_error());
else {
	$query = <<<END
	INSERT INTO `users`
	VALUES (
		'$orgID',
		'$userName',
		'$password'
		);
END;
	if (!mysql_query($query, $connection))
		die("Failed to Register User: " . mysql_error());
	
}

	echo "<p align = center >Registration Complete</p>";
	
mysql_close($connection);

?>

<div>
<ul>
<li align = "center"><?php echo $orgName; ?></li>
<li align = "center"><?php echo $firstName ." ". $lastName; ?></li>
<li align = "center"><?php echo "(".$areaCode.")".$prefix."-".$lineNumber; ?></li>
<li align = "center"><?php echo $streetAddress." ".$street2; ?></li>
<li align = "center"><?php echo $city.",".$state." ".$zip?>
<li align = "center"><?php echo $email; ?></li>
<li align = "center"><a><?php echo $website; ?></a></li>
<li align = "center"><?php echo $additional?>
<p align = "center">Your account has been created. You can now login <a href="login.php">here</a></p>
</ul>
</div>
<?php include("footer.php"); ?>